import iUser, { UserLogSchema } from 'src/api/user'
import { AppWidgetData } from 'src/store/widget/state'
import { defineComponent } from 'vue'

export default defineComponent({
  methods: {
    async openLink (app: AppWidgetData, location: JSON) {
      if (!app.appData) return
      if (app.appData.permalink) {
        window.open(app.appData.permalink, '_blank')
      }
      await iUser.postActivity({
        level: 1,
        type: 2,
        location: location,
        action: 'open-link',
        value: {
          id: app.id,
          type: app.type
        }
      })
      await this.$store.dispatch('widget/incAppClickCount', app)
    },
    async log (location: JSON, action: string, value: JSON, level: number, type: number) {
      if (!level) level = 1
      if (!type) type = 2
      await iUser.postActivity({
        level: level,
        type: type,
        location: location,
        action: action,
        value: value
      })
    },
    async log1 (log: UserLogSchema) {
      if (!log.level) log.level = 1
      if (!log.type) log.type = 2
      await iUser.postActivity(log)
    }
  }
})
